package com.pet.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.pet.system.controller.vo.OrderVo;
import com.pet.system.entity.Order;
import com.pet.system.mapper.OrderMapper;
import com.pet.system.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public Order getInfo(Long id) {
        return orderMapper.selectById(id);
    }

    @Override
    public PageInfo<Order> getPageList(OrderVo order) {
        LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .eq(null!=order.getAccounts(),Order::getAccounts,order.getAccounts())
                .eq(null!=order.getStatus(),Order::getStatus,order.getStatus())
                .eq(null!=order.getPetId(),Order::getPetId,order.getPetId())
                .eq(null!=order.getPayStatus(),Order::getPayStatus,order.getPayStatus())
        ;

        return PageHelper.startPage(order.getPageNo(), order.getPageSize())
                .doSelectPageInfo(() -> orderMapper.selectList(queryWrapper));
    }

    @Override
    public int remove(Long[] orderIds) {
        for (Long id : orderIds) {
            int i = orderMapper.deleteById(id);
        }
        return 1;
    }

    @Override
    public int edit(Order order) {
        return orderMapper.updateById(order);
    }

    @Override
    public int add(Order order) {
        order.setSubmitTime(new Date());
        return orderMapper.insert(order);
    }

    @Override
    public List<Map<String, Integer>> orderNum() {
        return orderMapper.orderNum();
    }

    @Override
    public List<Map<String, Integer>> staffOrder() {
        return  orderMapper.staffOrder();
    }
}
